﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZK.MyControl
{
     public  class MyMonthPicker : Label
    {

        public MyMonthPicker()
        {
            this.AutoSize = false;
            this.Size = new System.Drawing.Size(350, 50);
            this.Font = new System.Drawing.Font("宋体", 36, System.Drawing.FontStyle.Bold);
            this.Text = dateTime.ToString("yyyy-MM");
            this.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            this.BorderStyle = BorderStyle.FixedSingle;
            this.Click += MyMonthPicker_Click;
            base.Invalidate();
        }

        private DateTime dateTime = DateTime.Now;
        public DateTime DateTime
        {
            get
            {
                return dateTime;
            }
            set
            {
                dateTime = value;
                this.Text = dateTime.ToString("yyyy-MM");
                this.Invalidate();
                if (ValueChanged != null)
                {
                    ValueChanged(dateTime, null);
                }
            }
        }

        private void MyMonthPicker_Click(object sender, EventArgs e)
        {
            FrmMonthPicker frmMonthPicker = new FrmMonthPicker();
            frmMonthPicker.Datetime = DateTime;
            frmMonthPicker.ShowDialog();
            DateTime = frmMonthPicker.Datetime;
        }

        public EventHandler ValueChanged;
    }
}
